/*************************************************
Author: byron
Date: 11/06/2012
Description:
Notes: 
*************************************************/

#ifndef __CRoleInitCfg_h__
#define __CRoleInitCfg_h__

#include "CTArray.h"
#include "commclass.h"

class CRoleInitCfgData
{
public:
	CRoleInitCfgData() 
    {
		Clear();
	}

	virtual ~CRoleInitCfgData() 
    {
	}

	void Clear()
	{
		_bHasCfg = false;
		_uiID = 0;
		_iInt = 0;
		_iVit = 0;
		_iStr = 0;
		_iAgi = 0;
        _usHelmetId = 0;
        _usColthId = 0;
        _usWeaponId = 0;
        _usShoeId = 0;
        _iStatusGroupID = 0;
		_uiNormalSkill = 0;
		_uiAcadSkill = 0;
		_uiMagicSkill = 0;
        _stInitAttr.Clear();
	}

	bool HasCfg() const {return _bHasCfg;}

	bool IsValidID() const
    {
        return (_uiID >= CAREER_BEGIN && _uiID <= CAREER_END);
    }
    
    bool IsValidAttr()
    {
        return _stInitAttr.IsValidAttrValue();
    }

public:
	bool			_bHasCfg;
	unsigned int 	_uiID;
	int 			_iInt;				//智力
	int 			_iVit;				//体力
	int 			_iStr;				//力量
	int 			_iAgi;				//敏捷
    unsigned short  _usHelmetId;
    unsigned short  _usColthId;
    unsigned short  _usWeaponId;
    unsigned short  _usShoeId;
    int             _iStatusGroupID;
	unsigned int	_uiNormalSkill;		//普通技能
	unsigned int	_uiAcadSkill;		//学院技能
	unsigned int	_uiMagicSkill;		//幻化技能

    CPlayerAttr     _stInitAttr;
};

class CRoleInitCfg
{
public:
	CRoleInitCfg() 
    {
		_astRoleInitCfg.m_iUsedCount = _astRoleInitCfg.GetCount();
		for (int i = 0; i < _astRoleInitCfg.Size(); ++i)
		{
			_astRoleInitCfg[i].Clear();
		}
	}

	virtual ~CRoleInitCfg() 
    {
	}

	int AddConfig(CRoleInitCfgData& stCfgData)
	{
	    if (!stCfgData.HasCfg())
	    {
	        return ERROR_ROLE_INIT_EMPTY_CFG;
	    }

		if (!stCfgData.IsValidID())
		{
			return ERROR_ROLE_INIT_ID_INVALID;
		}

        if (!stCfgData.IsValidAttr())
        {
            return ERROR_ROLE_INIT_EMPTY_CFG;
        }

		if (_astRoleInitCfg[stCfgData._uiID - 1].HasCfg())
		{
	        return ERROR_ROLE_INIT_ID_REPEAT;
		}
	
	    _astRoleInitCfg[stCfgData._uiID - 1] = stCfgData;
	
	    return 0;
	} 
	
	int FindConfig(unsigned int uiID)
	{
	    if (uiID > CAREER_END || uiID < CAREER_BEGIN)
	    {
			return -1;
	    }
		if (!_astRoleInitCfg[uiID - 1].HasCfg())
		{
			return -1;
		}
	
	    return uiID - 1;
	}
	
	CRoleInitCfgData& GetConfig(int iIndex)
	{
	    return _astRoleInitCfg[iIndex];
	}
	
private:
    CTLib::CTArray<CRoleInitCfgData, CAREER_END>  _astRoleInitCfg;
};


#endif // CRoleInitCfg_h__

